package com.cs2340.taskplusplus;

import android.content.Context;

import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import com.google.android.maps.*;



public class MapViewMarkedDisplay extends MapActivity{

	private LocationManager locManager; 
	private LocationListener locListener;
	private MapController mc;
	private int lat, lon;
	private MapView mapView;
	
	
	@Override
	protected boolean isRouteDisplayed() 
	{
		return false;
	}
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.mapview);
	    mapView = (MapView) findViewById(R.id.mapview);
	    mapView.setBuiltInZoomControls(true);
	    
	    
		LocationManager locManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
		//LocationListener locListener = new LocListener();
		//locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, 1000, locListener);
	    
		lat = CurrentLocation.getLat();
		lon = CurrentLocation.getLon();
		GeoPoint point = new GeoPoint(lat,lon);
		
		mc = mapView.getController();
	    mc.setCenter(point);
	    mc.setZoom(17);
	    
	    //mapView.getOverlays().add(new CrosshairOverlay());
	    mapView.getOverlays().add(new DrawableMapOverlay(this, point, R.drawable.marker, CurrentLocation.getName()));
	    
	}
	
	public void onPause(){
		super.onPause();
		System.out.println("____________THIS____________");
		System.out.println(CurrentLocation.getLat());
		System.out.println(CurrentLocation.getLon());
		
		
		GeoPoint p = mapView.getMapCenter();
	    
	    
	    
	    //mapView.getProjection().toPixels(mapView.getMapCenter(), null);
    	if (p.getLatitudeE6() != CurrentLocation.getLat()){
    		System.out.println("LAT");
    		CurrentLocation.setLat(p.getLatitudeE6());
    	}		
    	if (p.getLongitudeE6() != CurrentLocation.getLon()){
    		System.out.println("LON");
    		CurrentLocation.setLon(p.getLongitudeE6());
    	}	
    
    	System.out.println(p.getLatitudeE6());
		System.out.println(p.getLongitudeE6());
    	System.out.println(CurrentLocation.getLat());
		System.out.println(CurrentLocation.getLon());
		
    	
	}	
	
	
	
}
